﻿using ExcellentProjectPlus.Dominio.Catalogos.Repositorios;
using ExcellentProjectPlus.Dominio.Catalogos.Repositorios.Catalogos;
using ExcellentProjectPlus.Infraestructura.Data.Catalogos.Repositorios;
using ExcellentProjectPlus.Infraestructura.Transversales.Logging;
using ExcellentProjectPlus.Infraestructura.Data.Catalogos.Modelo;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcellentProjectPlus.Infraestructura.Data.Catalogos.UnidadDeTrabajo
{
    public class UnidadDeTrabajoCatalogos
           : IUnidadDeTrabajoCatalogos, IDisposable
    {
        DbContext context { get; set; }
        ITraceManager _traceManager;

        private RepositorioCatalogos repositorioCatalogo;


        #region Constructores
        public UnidadDeTrabajoCatalogos(ITraceManager traceManager)
        {
            this._traceManager = traceManager;
            context = new CatalogosContext();
        }
        #endregion

        public IRepositorioCatalogos RepositorioCatalogos
        {
            get
            {
                if (this.repositorioCatalogo == null)
                {
                    this.repositorioCatalogo = new RepositorioCatalogos(context, _traceManager);
                }
                return repositorioCatalogo;
            }
        }
        public void Confirmar()
        {
            context.SaveChanges();
        }

        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }



    }
}
